package com.bidevalution.business.vote;

import com.bidevalution.business.enums.VoteOptionEnum;
import com.bidevalution.business.impl.BeExpertVoteServiceImpl;
import com.bidevalution.business.service.BeExpertVoteService;
import com.bidevalution.dao.entity.BeExpertVoteCallBack;
import com.bidevalution.dao.entity.BeSectionInfo;
import com.bidevalution.dao.mapper.BeSectionExpertInfoMapper;
import com.bidevalution.dao.mapper.BeSectionInfoMapper;
import com.qtp.core.model.Response;
import com.qtp.core.util.DateUtil;
import com.qtp.core.util.GsonUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 检查通过企业数_表决后_处理结果任务
 * @Date 2020-04-16 9:34
 * @Author lhl
 */
@Log4j2
@Component
public class UnitNumCheckNextJob extends BeExpertVoteServiceImpl {

    @Autowired
    BeSectionInfoMapper beSectionInfoMapper;
    @Autowired
    BeSectionExpertInfoMapper beSectionExpertInfoMapper;
    @Resource(name = "beExpertVoteService")
    BeExpertVoteService beExpertVoteService;

    @Override
    public Response toUpdateTheVote(List<BeExpertVoteCallBack> voteCallBackList) {
        log.info("LOG[]toUpdateTheVote[]{},params={}", "记录日志", GsonUtil.toJsonWithGson(voteCallBackList));
        BeSectionInfo sectionInfo = new BeSectionInfo();
        BeExpertVoteCallBack beExpertVoteCallBack = voteCallBackList.get(0);
        String voteResule = beExpertVoteCallBack.getVoteResule();
        String msg;
        if (VoteOptionEnum.NO_TY.getName().equals(voteResule)){
            sectionInfo.setSeqId(beExpertVoteCallBack.getSectionId());
            //结束流程
            sectionInfo.setReviewState(4);
            sectionInfo.setUpdateTime(DateUtil.now());
            beSectionInfoMapper.updateByPrimaryKeySelective(sectionInfo);
            msg = "{\"title\":\"本工程流标！\",\"msg\":\"经评标委员会一致意见，本工程有效投标数少于3家，作流标处理！\",\"buttonMap\":{\"right\":{\"urlAction\":\"Confirm\",\"show\":true,\"name\":\"确认\"}}}";
        }else {
            msg = "{\"title\":\"可继续评审！\",\"msg\":\"经评标委员会一致意见，本次投标具有竞争力，可继续评审！\",\"buttonMap\":{\"right\":{\"urlAction\":\"Confirm\",\"show\":true,\"name\":\"返回继续评审\"}}}";
        }
        beExpertVoteService.addVoteMsg(beExpertVoteCallBack.getSectionId(),msg);
        return Response.ok();
    }
}
